package com.shaoshaohuo.app.view;


import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.utils.ToastUtil;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

/**
 * @author yusonglin
 * @Des 消息dialog
 */
public class InputNumberDialog implements OnClickListener {

    private Dialog mDialog;

    private Context mContext;

    private View mContentView;
    
    private ImageView mDismissImage;
    private EditText mPwdEdit;
    private Button mPayButton;
    
    private OnBtClickListener mListener;

    public InputNumberDialog(Context context) {

        this.mContext = context;

        mDialog = new Dialog(mContext,R.style.Custom_dialog_style);
        mContentView = View.inflate(mContext, R.layout.message_pay_money, null);

        mDismissImage = (ImageView) mContentView.findViewById(R.id.imageview_dismiss);
        mPwdEdit = (EditText) mContentView.findViewById(R.id.edittext_input_pwd);
        mPayButton = (Button) mContentView.findViewById(R.id.button_next);
        
        WindowManager.LayoutParams localLayoutParams = mDialog.getWindow().getAttributes();
        mDialog.onWindowAttributesChanged(localLayoutParams);
        mDialog.setCanceledOnTouchOutside(false);
        mDialog.setCancelable(true);
        mContentView.setMinimumWidth(10000);
        mDialog.setContentView(mContentView);
        localLayoutParams.gravity = Gravity.CENTER;
        
        
        mDismissImage.setOnClickListener(this);
    }
    
    @Override
	public void onClick(View v) {
    	switch (v.getId()) {
		case R.id.imageview_dismiss:
			mDialog.dismiss();
			break;
		}
	}

    public void setCanceledOnTouchOutside(boolean canceled){
        mDialog.setCanceledOnTouchOutside(canceled);
    }

    public void setCancelable(boolean canceled){
        mDialog.setCancelable(canceled);
    }

    /**
     * 设置监听
     *
     * @param listener
     */
    public void setOnBtClickListener(OnBtClickListener listener) {
        this.mListener = listener;
        mPayButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
            	String pwd = mPwdEdit.getText().toString().trim();
            	if(TextUtils.isEmpty(pwd)){
            		ToastUtil.toast("请输入您的抢单金额");
            		return;
            	}
                mListener.onPayClick(Double.parseDouble(pwd));
                mDialog.dismiss();
            }
        });
    }

    public void show() {
        if (mDialog != null) {
            mDialog.show();
        }
    }

    public void dismiss() {
        if (mDialog != null) {
            mDialog.dismiss();
        }
    }

    /**
     * @ClassName: OnBtClickListener
     */
    public interface OnBtClickListener {
        void onPayClick(double pwd);
    }


}
